package br.com.main.client.system.morador;

import java.util.ArrayList;
import java.util.Date;

import br.com.main.client.system.botoes.Morador;
import br.com.main.client.system.botoes.Notificacao;
import br.com.main.client.system.morador.NotificacoesPresenterM.Display;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class NotificacoesViewM extends Composite implements Display{

	private HorizontalPanel panel;
	CellTable<Notificacao>tabelaNot = new CellTable<Notificacao>();
	ArrayList<Notificacao>notificacoes = new ArrayList<Notificacao>();
	TextBox tbSindico = new TextBox();
	TextArea tbDesc = new TextArea();
	Button btEnviar = new Button("Enviar");
	
	public NotificacoesViewM() {
		init();
		initWidget(panel);
	}

	private void init() {
		panel = new HorizontalPanel();
		panel.setStyleName("bordaDados");
		panel.setSpacing(20);
		tbSindico.setText("Sindico: ");
		
		VerticalPanel panelNot = new VerticalPanel();
		panelNot.setBorderWidth(1);
		tbDesc.setVisibleLines(5);
		tbDesc.setWidth("250px");
		tbDesc.addStyleName("textAreaDesc");
		
		criarTabelaNot();
		panelNot.add(new Label("Notificações"));
		panelNot.add(this.tabelaNot);
		
		VerticalPanel panelFazNot = new VerticalPanel();
		panelFazNot.setBorderWidth(1);
		
		panelFazNot.add(new Label("Notificar Sindico"));
		panelFazNot.add(new Label("Sindico"));
		panelFazNot.add(tbSindico);
		panelFazNot.add(new Label("Descrição"));
		panelFazNot.add(tbDesc);
		panelFazNot.add(btEnviar);
		
		
		panel.add(panelNot);
		panel.add(panelFazNot);
	}
	
	public void criarTabelaNot() {
		TextColumn<Notificacao> colNome = new TextColumn<Notificacao>() {
			
			@Override
			public String getValue(Notificacao arg0) {
				return arg0.getNomeNot();
			}
		};
		
		this.tabelaNot.addColumn(colNome,"Nome");
		
		TextColumn<Notificacao> colDesc = new TextColumn<Notificacao>() {
			
			@Override
			public String getValue(Notificacao arg0) {
				return arg0.getDesc();
			}
		};
		
		this.tabelaNot.addColumn(colDesc,"Descrição");
		
		TextColumn<Notificacao>colData = new TextColumn<Notificacao>() {
			
			@Override
			public String getValue(Notificacao arg0) {
				DateTimeFormat format = DateTimeFormat.getFormat("d/MM/y");
				String data = format.format(new Date(arg0.getDataNot()));
				return data;
			}
		};
		
		this.tabelaNot.addColumn(colData, "Data");
	}
	@Override
	public void setNotificacao(ArrayList<Notificacao> nots) {
		this.notificacoes = nots;
		
	}
	@Override
	public void atualizaTabelaNot() {
		this.tabelaNot.setRowCount(this.notificacoes.size());
		this.tabelaNot.setRowData(0, this.notificacoes);
		
	}

	@Override
	public TextArea getTbDesc() {
		return tbDesc;
	}
	@Override
	public Button getBtEnviar() {
		return btEnviar;
	}
	@Override
	public TextBox getTbSindico() {
		return tbSindico;
	}

}